
</html>
		<header>
			<meta charset="UTF-8">
		</header>
		<body>

		<textarea id="response" style="width:300px;height: 300px;border: 1px solid black;"></textarea>
		<input type="text" id="inputstr"/>

		<button onclick="send()">发送</button>

		<script type="text/javascript">
			var websocket = null;
			//建立websocket请求
			function buildWS(){
				if ('WebSocket' in window) {
					websocket = new WebSocket("ws://127.0.0.1:8088/hello");
					// 建立连接
					websocket.onopen = function(event){
						websocket.send(JSON.stringify({'type':'0','userId':'100'}));
					}

					//接收到推送消息
					websocket.onmessage = function(event){
						let textarea = document.getElementById("response");
						textarea.append(event.data);
						console.log(event.data);
					}

					websocket.onclose = function () {
						document.getElementById("response").innerText = "断开连接";
					}
				} else {
					alert('不支持websocket')
					return false;
				}
			}

			// 发送数据
			function send(){
				websocket.send(JSON.stringify({'type':'1', 'content':document.getElementById("inputstr").value}));
			}

			window.onload = function () {
				buildWS();
			}
		</script>
	</body>
</html>
